import Entity from "./Entity";

const {ccclass, property} = cc._decorator;

@ccclass
export default class Item extends cc.Component implements Entity {

    tiledLayer:cc.TiledLayer=null;

    isCanMove(v3: cc.Vec3): boolean {

        return true;
    }
    doEvent(v3: cc.Vec3,node:cc.Node){
        let gid=this.tiledLayer.getTileGIDAt(v3.x,v3.y);
        
        if(gid!=0){
            let tiled=this.tiledLayer.getTiledTileAt(v3.x,v3.y,false);
            this.tiledLayer.getProperties()
            this.pickUpItem(gid,v3);
        }
        return true;
    }


    onLoad () {
        let tild=this.node.getComponent(cc.TiledMap);
        this.tiledLayer=tild.getLayer('item');
    }

    start () {
    }

    pickUpItem(gid:number,v3: cc.Vec3){
        cc.log('pick up item gid:'+gid);
        this.tiledLayer.setTileGIDAt(0,v3.x,v3.y)
    }

    // update (dt) {}
}
